package com.cskaoyan.controller;

import com.cskaoyan.bean.Brand;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Map;

@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    MarketService marketService;
    @RequestMapping("list")
    public BaseRespVo getBrandList(Integer page,Integer limit,String sort, String order, Integer id, String name){

        Map<String, Object> brandMap = marketService.getBrandList(page, limit, sort, order, id, name);
        return BaseRespVo.ok(brandMap);
    }
    @RequestMapping("create")
    public BaseRespVo brandCreate(@RequestBody Brand brand){
        BaseRespVo baseRespVo = new BaseRespVo();
        brand.setDeleted(false);
        Brand brand1 = marketService.brandCreate(brand);
        baseRespVo.setData(brand1);
        return baseRespVo;
    }
    @RequestMapping("update")
    public BaseRespVo brandUpdate(@RequestBody Brand brand){
        BaseRespVo baseRespVo = new BaseRespVo();
        int i = marketService.brandUpdate(brand);
        if (i != 1){
            baseRespVo.setErrno(1);
            baseRespVo.setErrmsg("创建失败");
        }
        baseRespVo.setData(brand);
        return BaseRespVo.ok(baseRespVo.getData());
    }
    @RequestMapping("delete")
    public BaseRespVo brandDelete(@RequestBody Brand brand){
        BaseRespVo baseRespVo = new BaseRespVo();
        Integer i = marketService.brandDelete(brand);
        if (i != 1){
            baseRespVo.setErrno(1);
            baseRespVo.setErrmsg("删除失败");
        }
        return  BaseRespVo.ok();
    }

}
